<template>
	<view class="subsidy_box">
		<view class="head_box">
			<view class="show_box">
				<view class="show_item">
					<view class="num-label">{{headInfo.point}}</view>
					<view class="name-label">订单积分</view>
				</view>
				<view class="show_item">
					<view class="num-label">{{headInfo.total}}</view>
					<view class="name-label">补贴额度</view>
				</view>
				<view class="show_item">
					<view class="num-label">{{headInfo.platform}}</view>
					<view class="name-label">平台补贴</view>
				</view>
				<view class="show_item"
					@click="$util.redirectTo('/plugpages/subsidy/acceleration_details/acceleration_details')">
					<view class="num-label">{{headInfo.accelerate}}</view>
					<view class="name-label">加速补贴
						<image :src="$util.img('upload/uniapp/subsidy/menu_right@2x.png')" mode=""></image>
					</view>
				</view>
			</view>
			<view class="menu-box">
				<view class="menu-item" :class="current == index ? 'native' : ''" v-for="(item,index) in menus"
					:key="index" @click="selectMenu(index)">
					{{item}}
				</view>
			</view>
		</view>
		<mescroll-uni @getData="getData" ref="mescroll" top="442">
			<block slot="list">
				<block v-if="dataList.length > 0">
					<view class="list-box">
						<view class="list-item" v-for="(item,index) in dataList" :key="">
							<view class="part-one">
								<view class="part-o-left">
									<view class="type_line" :class="item.order_type != 1 ? 'blue' : ''">
										{{item.order_type == 1 ? '线上' : '线下'}}
									</view>
									<view class="order_label">{{item.order_no}}</view>
								</view>
								<view class="order_state" :class="item.state == 2 ? 'completed' : 0">
									{{stateText(item.state)}}
								</view>
							</view>
							<view class="content_box">
								<view class="orders-box">
									<view class="order-item">
										<view class="num_text">{{item.account}}</view>
										<view class="dec_text">订单积分</view>
									</view>
									<view class="order-item">
										<view class="num_text">{{item.total_expansion_value}}</view>
										<view class="dec_text">补贴额度</view>
									</view>
									<view class="order-item">
										<view class="num_text">{{item.platform}}</view>
										<view class="dec_text">平台补贴</view>
									</view>
									<view class="order-item"
										@click="$util.redirectTo('/plugpages/subsidy/accelerate_order_details/accelerate_order_details',{order_no:item.order_no})">
										<view class="num_text red">{{item.accelerate}}</view>
										<view class="dec_text">加速补贴
											<image :src="$util.img('upload/uniapp/subsidy/item_right@2x.png')" mode="">
											</image>
										</view>
									</view>
								</view>
								<block v-if="item.state == 2">
									<view class="finish_dec">{{item.total_expansion_value}}补贴额度将会通过消费券形式发放</view>
								</block>
								<block v-else-if="item.state == 1">
									<view class="progress-box">
										<view class="progress_num_text">补贴进度{{item.progress}}%</view>
										<view class="progress-view">
											<view class="native-progress" :style="{width:item.progress + '%'}"
												v-if="item.progress > 0">
												<view class="slider_box">{{item.progress}}%</view>
											</view>
										</view>
									</view>
								</block>
							</view>
							<view class="part-foot">
								<view class="part-foot-left" @click="toShop(item)">
									<image class="order-img" :src="$util.img(item.logo)" mode="aspectFill"></image>
									<view class="shop_name">{{item.site_name}}</view>
									<image class="right_icon"
										:src="$util.img('upload/uniapp/subsidy/item_right@2x.png')" mode=""></image>
								</view>
								<view class="time_label">{{$util.timeStampTurnTime(item.create_time)}}</view>
							</view>
						</view>
					</view>
				</block>
				<block v-else>
					<ns-empty :isIndex="false" :fixed="false" text="暂无数据"></ns-empty>
				</block>
			</block>
		</mescroll-uni>
		<loading-cover ref="loadingCover"></loading-cover>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				menus: ['全部', '加速中', '排队中', '已完成'],
				current: 0,
				dataList: [],
				headInfo: {}
			}
		},
		onLoad() {},
		methods: {
			getData(mescroll) {
				if (mescroll.num == 1) {
					this.getMemberHerd();
				}
				this.$api.sendRequest({
					url: '/expansion/api/Record/queuePage',
					data: {
						page: mescroll.num,
						page_size: mescroll.size,
						type: this.current
					},
					success: res => {
						let newArr = [];
						let msg = res.message;
						if (res.code == 0 && res.data) {
							newArr = res.data.list;
						} else {
							this.$util.showToast({
								title: msg
							});
						}
						if (mescroll.endSuccess) mescroll.endSuccess(newArr.length);
						//设置列表数据
						if (mescroll.num == 1) this.dataList = []; //如果是第一页需手动制空列表
						this.dataList = this.dataList.concat(newArr); //追加新数据
						if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
					},
					fail() {
						//联网失败的回调
						if (mescroll.endErr) mescroll.endErr();
						if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
					}
				})
			},
			getMemberHerd() {
				this.$api.sendRequest({
					url: '/expansion/api/Record/getMemberHerd',
					success: res => {
						if (res.code == 0 && res.data) {
							this.headInfo = res.data;
						}
					}
				})
			},
			toShop(item) {
				if (item.order_type == 2) {
					this.$util.redirectTo('/plugpages/subsidy/queuing_subsidy/queuing_subsidy', {
						site_id: item.site_id
					});
				} else {
					this.$util.redirectTo('/otherpages/shop/index/index', {
						site_id: item.site_id
					});
				}
			},
			selectMenu(index) {
				if (this.current != index) {
					this.current = index;
					this.$refs.mescroll.refresh();
				}
			},
			stateText(state) {
				if (state == 0) {
					return '排队中';
				} else if (state == 1) {
					return '加速中';
				} else {
					return '已完成';
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.subsidy_box {
		.head_box {
			padding: 24rpx 24rpx 0 24rpx;

			.show_box {
				width: 100%;
				height: 312rpx;
				border-radius: 20rpx;
				background: linear-gradient(316deg, #F84907 0%, #FD791E 100%);
				display: flex;
				flex-wrap: wrap;
				padding: 30rpx 0;

				.show_item {
					width: 50%;
					height: 50%;
					display: flex;
					align-items: center;
					flex-direction: column;
					justify-content: center;

					.num-label {
						font-family: PingFang SC, PingFang SC;
						font-weight: 500;
						font-size: 40rpx;
						line-height: 50rpx;
						color: #FFFFFF;
					}

					.name-label {
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						font-size: 24rpx;
						color: rgba(255, 255, 255, 0.7);
						display: flex;
						align-items: center;

						image {
							width: 32rpx;
							height: 32rpx;
						}
					}
				}
			}

			.menu-box {
				padding-top: 16rpx;
				width: 100%;
				height: 106rpx;
				display: flex;
				align-items: center;

				.menu-item {
					width: 25%;
					height: 100%;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					font-size: 28rpx;
					color: #222222;
					line-height: 42rpx;
					display: flex;
					align-items: center;
					justify-content: center;

					&.native {
						font-family: PingFang SC, PingFang SC;
						font-weight: 500;
						font-size: 32rpx;
						color: #222222;
						line-height: 42rpx;
					}
				}
			}
		}

		.list-box {
			padding: 0 24rpx;

			.list-item {
				padding: 28rpx 24rpx 34rpx 24rpx;
				background-color: #FFFFFF;
				border-radius: 20rpx;
				margin-bottom: 24rpx;

				.part-one {
					display: flex;
					align-items: center;
					justify-content: space-between;

					.part-o-left {
						display: flex;
						align-items: center;

						.type_line {
							font-family: PingFang SC, PingFang SC;
							font-weight: 400;
							font-size: 22rpx;
							color: #00B42A;
							padding: 0 8rpx;
							border-radius: 4rpx;
							// width: 64rpx;
							background-color: #E8FFEA;

							&.blue {
								background: #E8F3FF;
								color: #165DFF;
							}
						}

						.order_label {
							margin-left: 8rpx;
							font-family: PingFang SC, PingFang SC;
							font-weight: 400;
							font-size: 28rpx;
							color: #666666;
						}
					}

					.order_state {
						font-family: PingFang SC, PingFang SC;
						font-weight: 500;
						font-size: 28rpx;
						color: #F53F3F;

						&.completed {
							color: #666666;
						}
					}
				}

				.content_box {
					margin-top: 24rpx;
					padding: 28rpx 24rpx;
					background-color: #F2F3F5;
					border-radius: 12rpx;

					.orders-box {
						display: flex;

						.order-item {
							width: 25%;
							display: flex;
							align-items: center;
							// justify-content: center;
							flex-direction: column;

							.num_text {
								font-family: PingFang SC, PingFang SC;
								font-weight: 500;
								font-size: 32rpx;
								color: #222222;
								line-height: 46rpx;
							}

							.red {
								color: #F53F3F;
							}

							.dec_text {
								font-family: PingFang SC, PingFang SC;
								font-weight: 400;
								font-size: 24rpx;
								color: #999999;
								display: flex;
								align-items: center;

								image {
									width: 32rpx;
									height: 32rpx;
								}
							}
						}
					}

					.finish_dec {
						margin-top: 32rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						font-size: 24rpx;
						color: #666666;
					}
				}

				.part-foot {
					margin-top: 28rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;

					.part-foot-left {
						display: flex;
						align-items: center;

						.order-img {
							width: 40rpx;
							height: 40rpx;
							border-radius: 50%;
							background-color: yellowgreen;
						}

						.shop_name {
							font-family: PingFang SC, PingFang SC;
							font-weight: 400;
							font-size: 24rpx;
							color: #666666;
							margin: 0 8rpx;
						}
					}

					.time_label {
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						font-size: 24rpx;
						color: #999999;
					}
				}
			}
		}
	}

	.progress-box {
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin-top: 38rpx;

		.progress_num_text {
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			font-size: 24rpx;
			color: #F53F3F;
			line-height: 34rpx;
		}

		.progress-view {
			width: 400rpx;
			height: 24rpx;
			background: #DCDCDC;
			border-radius: 38rpx;

			.native-progress {
				background-color: #F53F3F;
				height: 100%;
				border-radius: 38rpx;
				position: relative;

				.slider_box {
					position: absolute;
					right: -16rpx;
					top: -6rpx;
					width: 68rpx;
					height: 36rpx;
					background: #F53F3F;
					border-radius: 60rpx 60rpx 60rpx 60rpx;
					border: 2rpx solid #FFFFFF;

					font-family: PingFang SC, PingFang SC;
					font-weight: 500;
					font-size: 22rpx;
					color: #FFFFFF;
					line-height: 30rpx;
					display: flex;
					align-items: center;
					justify-content: center;
				}
			}
		}
	}

	.right_icon {
		width: 32rpx;
		height: 32rpx;
	}

	page {
		background-color: #F2F3F5;
	}

	view {
		box-sizing: border-box;
	}
</style>